package com.example.redcultural;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;


public class study extends Fragment {


    private OnFragmentInteractionListener mListener;
    TextView video_left,news_right;
    ImageView imageView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_study, container, false);
        ListView video_list = view.findViewById(R.id.video_list);
        String[] title = {
                "享誉中外的科学家和教育家--卢嘉锡",
                "生是为中国 死是为中国--刘伯坚","中国工人运动的杰出领袖--邓发"};
        String[] url = {"https://video.xuexi.cn/video/1001/p/8562cab2364c4e9db069dc88c6116db8-96ea742c5ace49b9ad8d194c786fb39d-2.mp4",
        "https://video.xuexi.cn/customerTrans/5fe46739b9b2bda7e29d0210237f56e1/5686574a-16230dcb540-0005-0cf3-24e-05740.mp4",
};

        List<StudyContent> studyContents = new ArrayList<>();
video_left=view.findViewById(R.id.video_left);
news_right=view.findViewById(R.id.news_right);
imageView=view.findViewById(R.id.video_image);
        for (int i = 0; i < url.length; i++) {
            StudyContent studyContent = new StudyContent();
            studyContent.setTitle(title[i]);
            studyContent.setVideoUrl(url[i]);
            studyContents.add(studyContent);
        }
        video_list.setAdapter(new video_Adapter(getContext(), studyContents));
        video_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(),Videos.class);
                startActivity(intent);

            }
        });
        news_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(),News.class);

                startActivity(intent);

            }
        });
        return view;
    }


    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    public interface OnFragmentInteractionListener {
        void onFragmentInteraction(Uri uri);
    }
}
